package function.listen;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import frame.master;
import frame.data.contrldata;
/**
 * 行号
 * @author Administrator
 *
 */
public class textarea2listen {
	private int oldlines=0;
	public textarea2listen() {
		contrldata.jtl=new JTextArea();
		contrldata.jtl.setFont(new Font(master.set.getNowziti(),master.set.getPlain(),master.set.getFontsize()));
		contrldata.jtl.append("1\n");
		contrldata.jtl.setEditable(false);
		contrldata.jtl.setCaretColor(Color.white);
		contrldata.jtl.setForeground(new Color(147,147,147));
		contrldata.jsl=new JScrollPane(contrldata.jtl);
		contrldata.jsl.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		contrldata.jsl.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
		contrldata.jsl.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, new Color(188,188,188)));
		if(!master.set.isIsshowlinenum())contrldata.jsl.setPreferredSize(new Dimension(0, master.HEIGHT));
		else contrldata.jsl.setPreferredSize(
				new Dimension(
						String.valueOf(contrldata.jt.getLineCount()).length()*(int)(master.set.getFontsize()*0.7),master.HEIGHT));
		
	}
	public void updatelinenum(master ma) {
		int w=contrldata.jt.getLineCount();
		contrldata.jsl.setPreferredSize(new Dimension(String.valueOf(w).length()*(int)(master.set.getFontsize()*0.7), contrldata.jsl.getHeight()));
		if(w!=oldlines) {
			contrldata.jtl.setText("");
			for(int i=1;i<=w;i++)contrldata.jtl.append(i+"\n");
			oldlines=w;
		}
		ma.validate();
		contrldata.fileinfo.updateUI();
	}
}
